Using Scriptrunner with Behaviours to Show/Hide a Multiline Text Field Based on Checkbox Selection

If you’re working with Jira and want to create a dynamic form that shows or hides a multiline text field when a specific checkbox option is selected, Scriptrunner with Behaviours is your go-to solution. In this guide, we’ll walk through how to configure this functionality using a script.

Prerequisites

  1. Jira with Scriptrunner installed.
  2. Basic knowledge of Jira custom fields and scripting.

Step-by-Step Guide

  1. Create the Custom Fields:
    • Go to your Jira administration settings and create a Checkbox custom field. Let’s name it Options.
    • Add options to this field, including an option named “Others”.
    • Create a Multiline Text Field custom field. Let’s name it Details.
  2. Add the Fields to Your Screen:
    • Ensure that both the Options and Details fields are added to the relevant screens where you want this behaviour to be applied.
  3. Navigate to Scriptrunner Behaviours:
    • Go to the Scriptrunner section in Jira administration.
    • Click on “Behaviours” and then “Add Behaviour”.
  4. Configure the Behaviour:
    • Select the appropriate project and issue type for this behaviour.
    • Add a mapping for the screen where your fields are located.
  5. Add a Server-Side Script:
    • In the Behaviours configuration, click on the “Options” field.
    • Add the following server-side script to handle the show/hide logic:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import static com.atlassian.jira.issue.IssueFieldConstants.*

def optionsField = getFieldByName("Options")
def detailsField = getFieldByName("Details")

def optionsValue = optionsField.getValue() as List

if (optionsValue.contains("Others")) {
detailsField.setHidden(false)
detailsField.setRequired(true)
} else {
detailsField.setHidden(true)
detailsField.setRequired(false)
}

This script does the following:

  • Retrieves the Options field value.
  • Checks if the “Others” option is selected.
  • If “Others” is selected, the Details field is shown and made required.
  • If “Others” is not selected, the Details field is hidden and not required.
  1. Test Your Configuration:
    • Create or edit an issue in the project and issue type where this behaviour is applied.
    • Check the Options field and select “Others”. The Details field should appear.
    • Deselect “Others” to see the Details field disappear.

Conclusion

By using Scriptrunner with Behaviours, you can create dynamic and responsive forms in Jira that enhance user experience and data collection. This guide provided a simple example of showing or hiding a multiline text field based on a checkbox selection. Experiment with other conditions and field types to further customize your Jira workflows!

Feel free to leave a comment below if you have any questions or need further assistance!

Screenshots with similar example:

  • You can set Hidden the field as default in the initialiser
  • In the field script, in this case “Type of Product”, the imports in the code are not needed

Post by MrAddon by TecnoFor by Sngular

.

#AtlassianCreator #Jira #Scriptrunner #Behaviours #MultilineTextField #Checkbox #CustomFields #JiraAdministration #JiraCustomization #DynamicForms #JiraScripting #WorkflowAutomation #JiraTips #Atlassian #JiraPlugins #IssueTracking

.'s avatar
Posted by:.

Leave a comment